package org.lex.reflect.browsing.util;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class IconCache {
	public static final String INHERIT = "inherit.png";
	public static final String SUPER_TYPE = "supertype.png";
	public static final String CLASS = "class.png";
	public static final String ENUM = "enum.png";
	public static final String INTERFACE = "interface.png";
	public static final String PACKAGE = "package.png";
	public static final String ABSTRACT_CLASS = "abstract.class.png";
	public static final String SHOW_ALL = "showall.png";
	public static final String SORT = "sort.png";
	// =====================================================
	private static final String PATH = "/org/lex/reflect/browsing/resources/";
	private static final ConcurrentMap<String, Icon> cache = new ConcurrentHashMap<String, Icon>(20);

	private IconCache() {
	}

	public static Icon getIcon(String key) {
		Icon icon = cache.get(key);
		if (null == icon) {
			icon = new ImageIcon(IconCache.class.getResource(PATH + key));
			cache.put(key, icon);
		}
		return icon;
	}
}
